package com.aos.erp.manager.rpc;

import com.aos.erp.common.bean.PageBean;
import com.aos.erp.manager.dto.NoticeDetailDTO;
import com.aos.erp.manager.model.notice.NoticeInfo;
import com.aos.erp.manager.model.notice.vo.NoticeConditionVo;
import com.aos.erp.manager.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = {"服务接口：通知公告接口"})
@RestController
@RequestMapping("/service/notice")
public class RpcNoticeController {

    @Autowired
    private NoticeService noticeService;

    @ApiOperation(value = "查询所有公告列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex", value = "当前页", required = true, dataType = "Integer", defaultValue = "1", paramType = "Query"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true, dataType = "Integer", defaultValue = "20", paramType = "Query"),
            @ApiImplicitParam(name = "noticeTitle", value = "公告标题", dataType = "String", paramType = "Query"),
            @ApiImplicitParam(name = "noticeContent", value = "公告内容", dataType = "String", paramType = "Query"),
            @ApiImplicitParam(name = "fromTime", value = "发布开始时间", dataType = "String", paramType = "Query"),
            @ApiImplicitParam(name = "toTime", value = "发布截止时间", dataType = "String", paramType = "Query"),
            @ApiImplicitParam(name = "orgId", value = "组织ID", dataType = "Long", paramType = "Query")
    })
    @PostMapping("/list")
    public PageBean<NoticeDetailDTO> listNotice(@RequestBody NoticeConditionVo params) {
        return noticeService.findByPage(params);
    }

    @ApiOperation(value = "查看公告详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dataId", value = "公告ID", required = true, dataType = "Long", paramType = "Query")
    })
    @PostMapping("/preview")
    public NoticeInfo previewNotice(@RequestBody Long dataId){
        return noticeService.getNoticeById(dataId);
    }
}
